 var pageSize01;
 var u_id=null;
 var uname=null;
 var upassword=null;
 var sex=null;
 var utelephone=null;
 var birthday=null;
 var deptList=null;
 var jobList=null;
$(function () {
    $.ajax({
        url: "/customCount02",      //请求接口的地址
        type: "GET",
        data: {
            "current": 1
        },
        dataType: "json",
        success: function (res) {
            $("#tbList").html("")
            var uui = 0;
            var dd = res;
            var total00=parseInt(dd.total);
            for (var i in dd.records) {
                if (i>1&&dd.records[i].customname==dd.records[i-1].customname){
                    total00=parseInt(total00)-parseInt(dd.records[i].orderNumbers)
                    continue;
                }
                var tr1 = "<tr></tr>";
                $("#tbList").append(tr1);
                var li = $("#tbList tr").eq(i);
                uui += 1;
                var str1 = "<td>" + uui + "</td>";
                str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                str1 += "<td>" + dd.records[i].site + "</td>";
                str1 += "<td>" + dd.records[i].orderNumbers + "</td>";
                str1 += "<td>" + dd.records[i].prototal + "</td>";
                str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                li.prepend(str1);
            }

            $('.blue').eq(0).text(dd.total)
            $('.blue').eq(1).text(dd.current)
            cliOrder()
            pageSize01=Number(dd.pages)
            var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
            if (pageSize01 >= 3) {
                for (var i = 1; i <= pageSize01; i++) {
                    if (i == pageSize01) {
                        pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                    } else {
                        pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                    }
                    if (i == pageSize01 - 2) {
                        pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                        pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                        break;
                    }

                }
            } else {
                for (var i = 1; i <= pageSize01; i++) {
                    if (i == pageSize01) {
                        pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                    } else {
                        pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                    }
                }
            }
            pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
            $('.paginList').html(pageStr)
            pageOnclik0101()
        }, error: function (r) {
            alert("!!!")
        }
    })
    onclPro()
    cliOrder()
    checkCustomName()
    submitChatAtByCondition()
})

// 根据省确定城市
function onclPro() {
    $("#province").blur(function () {
        // var a = $("#province").children("#orderid01").html();
        var prov01 = $("#province option:selected").text();
        $.ajax({
            url: "/cityByProvince1/" + prov01,      //请求接口的地址
            type: "GET",
            success: function (res) {

                $("#city1").html("")
                var st1 = " <option>请选择城市</option>";
                $("#city1").append(st1);
                for (var i in res) {
                    // alert(res[i].cname)
                    var tr1 = "<option>" + res[i].cname + "</option>";
                    $("#city1").append(tr1);

                }
            }
        })

    });
}

//正则，验证名字
function checkCustomName() {
    $("#customName").blur(function () {
        var str = $("#customName").val();
        var han = /^[\u4e00-\u9fa5]+$/;
        if (!han.test(str)) {
            alert("请输入公司名");
            var str = $("#customName").val("");
            return false;
        } else {
            return true;
        }
        ;
    })
}

//查询
function submitChatAtByCondition() {
    $("#chatMoreByCondition").click(function () {
        var Customname = $("#customName").val();
        var province = $("#province option:selected").text();
        var city1 = $("#city1 option:selected").text();
        var date1 = $("#date1").val();
        var date2 = $("#date2").val();
        if (province == "请选择省份") {
            province =''
        }
        if (city1 == "请选择城市") {
            city1 = ''
        }
        if (province==''&&Customname==''&&date1==''&&date2==''){
            alert("请选择查询条件")
        }
        $.ajax({
            url: "/customCountByCondition",      //请求接口的地址
            type: "post",
            data: {
                "pName": province,
                "cName": city1,
                "customname": Customname,
                "time01": date1,
                "time02": date2,
            },
            dataType: "json",
            success: function (res) {
                $("#tbList").html("")
                var uui = 0;
                var dd = res;
                var total00=parseInt(dd.total);
                for (var i in dd.records) {
                    if (i>1&&dd.records[i].customname==dd.records[i-1].customname){
                        total00=parseInt(total00)-parseInt(dd.records[i].orderNumbers)
                        continue;
                    }
                    var tr1 = "<tr></tr>";
                    $("#tbList").append(tr1);
                    var li = $("#tbList tr").eq(i);
                    uui += 1;
                    var str1 = "<td>" + uui + "</td>";
                    str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                    str1 += "<td>" + dd.records[i].site + "</td>";
                    str1 += "<td>" + dd.records[i].orderNumbers + "</td>";
                    str1 += "<td>" + dd.records[i].prototal + "</td>";
                    str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                    li.prepend(str1);
                }
                $('.blue').eq(0).text(total00)
                $('.blue').eq(1).text(dd.current)
                cliOrder()
                pageSize01=Number(dd.pages)
                var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
                if (pageSize01 >= 3) {
                    for (var i = 1; i <= pageSize01; i++) {
                        if (i == pageSize01) {
                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                        } else {
                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                        }
                        if (i == pageSize01 - 2) {
                            pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                            pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                            break;
                        }

                    }
                } else {
                    for (var i = 1; i <= pageSize01; i++) {
                        if (i == pageSize01) {
                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                        } else {
                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                        }
                    }
                }
                pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
                $('.paginList').html(pageStr)
                pageOnclik0101()
            }, error: function (r) {
                alert("!!!")
            }
        })
    })
}

//点击详情
function cliOrder() {
    $(".tablelink").click(function () {
        var b001 = $(this).parent().parent().children("#custname01").text();
        // var b001 = $(this).parent().parent().children("#cusname01").text();
        sessionStorage.removeItem("b1");
        sessionStorage.setItem("b1", JSON.stringify(b001));
    })
}

//分页点击
function pageOnclik0101() {
    $(".paginItem").click(function () {
        var click = $(this).children("a").text();
        var current = $('.blue').eq(1).text();
        if (current == click) {
            $(this).children("a").addClass("more")
        } else {
            if (click == "...") {
            } else if (click == '') {
                if ('<a href="javascript:;"><span class="pagepre"></span></a>' == $(this).html()) {
                    if (current != 1) {
                        current -= 1;
                        $("#tbList").html("")
                        $.ajax({
                            url: "/customCount",      //请求接口的地址
                            type: "GET",
                            data: {
                                "current": current
                            },
                            dataType: "json",
                            success: function (res) {
                                $("#tbList").html("")
                                var uui = 0;
                                var dd = res;
                                var total00=parseInt(dd.total);
                                for (var i in dd.records) {
                                    if (i>1&&dd.records[i].customname==dd.records[i-1].customname){
                                        total00=parseInt(total00)-parseInt(dd.records[i].orderNumbers)
                                        continue;
                                    }
                                    var tr1 = "<tr></tr>";
                                    $("#tbList").append(tr1);
                                    var li = $("#tbList tr").eq(i);
                                    uui += 1;
                                    var str1 = "<td>" + uui + "</td>";
                                    str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                                    str1 += "<td>" + dd.records[i].site + "</td>";
                                    str1 += "<td>" + dd.records[i].orderNumbers + "</td>";
                                    str1 += "<td>" + dd.records[i].prototal + "</td>";
                                    str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                                    li.prepend(str1);
                                }
                                $('.blue').eq(0).text(total00)
                                $('.blue').eq(1).text(dd.current)
                                cliOrder()
                                pageSize01=Number(dd.pages)
                                var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
                                if (pageSize01 >= 3) {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                        if (i == pageSize01 - 2) {
                                            pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                                            break;
                                        }

                                    }
                                } else {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                    }
                                }
                                pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
                                $('.paginList').html(pageStr)
                                pageOnclik0101()
                            }, error: function (r) {
                                alert("!!!")
                            }
                        })
                    }
                } else {
                    if (current != pageSize01) {
                        var currentInt=parseInt(current)+1;
                        $("#tbList").html("")
                        $.ajax({
                            url: "/customCount",      //请求接口的地址
                            type: "GET",
                            data: {
                                "current": currentInt
                            },
                            dataType: "json",
                            success: function (res) {
                                $("#tbList").html("")
                                var uui = 0;
                                var dd = res;
                                var total00=parseInt(dd.total);
                                for (var i in dd.records) {
                                    if (i>1&&dd.records[i].customname==dd.records[i-1].customname){
                                        total00=parseInt(total00)-parseInt(dd.records[i].orderNumbers)
                                        continue;
                                    }
                                    var tr1 = "<tr></tr>";
                                    $("#tbList").append(tr1);
                                    var li = $("#tbList tr").eq(i);
                                    uui += 1;
                                    var str1 = "<td>" + uui + "</td>";
                                    str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                                    str1 += "<td>" + dd.records[i].site + "</td>";
                                    str1 += "<td>" + dd.records[i].orderNumbers + "</td>";
                                    str1 += "<td>" + dd.records[i].prototal + "</td>";
                                    str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                                    li.prepend(str1);
                                }
                                $('.blue').eq(0).text(total00)
                                $('.blue').eq(1).text(dd.current)
                                cliOrder()
                                pageSize01=Number(dd.pages)
                                var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
                                if (pageSize01 >= 3) {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                        if (i == pageSize01 - 2) {
                                            pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                                            break;
                                        }

                                    }
                                } else {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                    }
                                }
                                pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
                                $('.paginList').html(pageStr)
                                pageOnclik0101()
                            }, error: function (r) {
                                alert("!!!")
                            }
                        })
                    }
                }

            } else {
                $("#tbList").html("")
                $.ajax({
                    url: "/customCount",      //请求接口的地址
                    type: "GET",
                    data: {
                        "current": click
                    },
                    dataType: "json",
                    success: function (res) {
                        $("#tbList").html("")
                        var uui = 0;
                        var dd = res;
                        var total00=parseInt(dd.total);
                        for (var i in dd.records) {
                            if (i>1&&dd.records[i].customname==dd.records[i-1].customname){
                                total00=parseInt(total00)-parseInt(dd.records[i].orderNumbers)
                                continue;
                            }
                            var tr1 = "<tr></tr>";
                            $("#tbList").append(tr1);
                            var li = $("#tbList tr").eq(i);
                            uui += 1;
                            var str1 = "<td>" + uui + "</td>";
                            str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                            str1 += "<td>" + dd.records[i].site + "</td>";
                            str1 += "<td>" + dd.records[i].orderNumbers + "</td>";
                            str1 += "<td>" + dd.records[i].prototal + "</td>";
                            str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                            li.prepend(str1);
                        }
                        $('.blue').eq(0).text(total00)
                        $('.blue').eq(1).text(dd.current)
                        cliOrder()
                        pageSize01=Number(dd.pages)
                        var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
                        if (pageSize01 >= 3) {
                            for (var i = 1; i <= pageSize01; i++) {
                                if (i == pageSize01) {
                                    pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                } else {
                                    pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                }
                                if (i == pageSize01 - 2) {
                                    pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                                    pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                                    break;
                                }

                            }
                        } else {
                            for (var i = 1; i <= pageSize01; i++) {
                                if (i == pageSize01) {
                                    pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                } else {
                                    pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                }
                            }
                        }
                        pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
                        $('.paginList').html(pageStr)
                        pageOnclik0101()
                    }, error: function (r) {
                        alert("!!!")
                    }
                })
            }
        }

    })
}


